package main

import (
	"log"

	_ "github.com/go-sql-driver/mysql"
	"github.com/jmoiron/sqlx"
)

// 引入sqlx：
func initializeDatabase() (err error) {
	dsn := "root:123456@tcp(localhost:3306)/test?charset=utf8mb4&parseTime=True&loc=Local"
	connect, err := sqlx.Connect("mysql", dsn)
	if err != nil {
		log.Println("connect 2 database failed, err：%v\n", err)
		return
	}
	connect.SetMaxOpenConns(10)
	connect.SetMaxIdleConns(10)
	return nil

}
func main() {
	if err := initializeDatabase(); err != nil {
		panic(err)
	}
	log.Println("connect 2 database success.")
}
